package com.jzlw.cloud.platform.apple.util;

import com.jzlw.cloud.platform.apple.javaBean.commonbean.CommonBean;
import com.jzlw.cloud.platform.apple.javaBean.consigneeData.ConsigneeBean;
import com.jzlw.cloud.platform.apple.javaBean.consigneeData.ConsigneeEnterpriseBean;
import com.jzlw.cloud.platform.apple.javaBean.shiperData.ShipperBean;
import com.jzlw.cloud.platform.apple.javaBean.shiperData.ShipperEnterpriseBean;
import com.google.common.io.Resources;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p/>
 * <li>Description:验证企业数据（json格式）</li>
 * <li>@author: wangyuanhua</li>
 * <li>Date: 2017/11/2 0002 下午 8:58</li>
 */

public class CheckJsonExpress {

    private static final Logger LOGGER = LoggerFactory.getLogger(CheckJsonExpress.class);
    private int status = 0;
    private StringBuffer errMsg;
    private List<Map> recordErrMsg;

    /**
     * 验证Json格式及企业数据的合法性
     *
     * @param paramsJson json字符串
     * @return Map  返回的集合
     * @throws Exception 解析JSON异常
     */
    public Map validateJsonParams(String paramsJson, Boolean isCheck) throws Exception {
        recordErrMsg = new ArrayList<Map>();
        errMsg = new StringBuffer();
        Map retMap = new HashMap();
        //LOGGER.info("=============字段校验类传入的原始字符串为："+paramsJson);
        //1.首先验证传递的参数是否为空，为空则抛异常
        if (StringUtils.isBlank(paramsJson)) {
            status = 7;
            errMsg.append("企业数据验证接口没有接收到任何数据");
            LOGGER.error("企业数据验证接口没有接收到任何数据");
            retMap.put("total_accessed_num", 0);
            retMap.put("success_accessed_num", 0);
            retMap.put("fail_accessed_num", 0);
            retMap.put("status", status);
            retMap.put("errMsg", errMsg.toString());
            return retMap;
        }
        CommonBean commonBean;
        ShipperEnterpriseBean shiperEmterpriseBean;
        ConsigneeEnterpriseBean consigneeEnterpriseBean;
        Gson gson = new Gson();
        if (!isCheck) {
            //这里由于不详细检查每一个字段。所以利用发货Bean，简单校验发货的订单的数量与用户设置的数据量是否吻合即可
            ShipperEnterpriseBean noCheckCommonFields = gson.fromJson(paramsJson, ShipperEnterpriseBean.class);
            Integer count = noCheckCommonFields.getTotal_pushed_num();
            List list = noCheckCommonFields.getRecord_list();
            if (list != null && list.size() > 0) {
                if (count != list.size()) {
                    status = 13;
                    LOGGER.error("推送总量为：" + count + ",但实际集合数据中推送的总量为："
                            + list.size() + "，二者不相等.不予推送");
                    errMsg.append("推送总量为：" + count + ",但实际集合数据中推送的总量为："
                            + list.size() + "，二者不相等.不予推送");
                    retMap.put("total_accessed_num", 0);
                    retMap.put("success_accessed_num", 0);
                    retMap.put("status", status);
                    retMap.put("errMsg", errMsg.toString());
                    return retMap;
                }
            }
            retMap.put("total_accessed_num", count);
            retMap.put("success_accessed_num", count);
            retMap.put("status", status);
            retMap.put("errMsg", errMsg.toString());
            return retMap;
        }


        //2.解析输入的json字符串为指定的json对象
        try {
            commonBean = gson.fromJson(paramsJson, CommonBean.class);
            Integer pushed_data_type = commonBean.getPushed_data_type();
           /* 发货信息	0
              收货信息	1
            发货更新信息	2
            收货更新信息	3*/
            if (0 == pushed_data_type || 2 == pushed_data_type) {
                //发货信息解析
                shiperEmterpriseBean = gson.fromJson(paramsJson, ShipperEnterpriseBean.class);
                retMap = this.checkEveryField(shiperEmterpriseBean, gson, retMap, pushed_data_type);
            } else if (1 == pushed_data_type || 3 == pushed_data_type) {
                //收货信息解析
                consigneeEnterpriseBean = gson.fromJson(paramsJson, ConsigneeEnterpriseBean.class);
                retMap = this.checkEveryField(consigneeEnterpriseBean, gson, retMap, pushed_data_type);
            }
        } catch (JsonSyntaxException e1) {
            status = 8;
            LOGGER.error("输入的json字符串解析异常！请核实Json数据格式的合法性", e1);
            errMsg.append("输入的json字符串解析异常！请核实Json数据格式的合法性");
            retMap.put("total_accessed_num", 0);
            retMap.put("success_accessed_num", 0);
            retMap.put("fail_accessed_num", 0);
            retMap.put("status", status);
            retMap.put("errMsg", errMsg.toString());
            return retMap;
        }
        return retMap;
    }

    /**
     * 校验每一个字段
     */
    private Map<String, Object> checkEveryField(Object param, Gson gson, Map retMap, Integer pushed_data_type) {
        ShipperEnterpriseBean paramShiper = null;
        ConsigneeEnterpriseBean consigBean = null;
        Integer total_pushed_num = null;
        List<ShipperBean> recordShippers = null;
        List<ConsigneeBean> recordConsignees = null;
        int iCount = 0;
        //企业侧推送的数据类型
        if (0 == pushed_data_type || 2 == pushed_data_type) {
            paramShiper = (ShipperEnterpriseBean) param;
            total_pushed_num = paramShiper.getTotal_pushed_num();
            recordShippers = paramShiper.getRecord_list();
            iCount = recordShippers.size();
        } else if (1 == pushed_data_type || 3 == pushed_data_type) {
            consigBean = (ConsigneeEnterpriseBean) param;
            total_pushed_num = consigBean.getTotal_pushed_num();
            recordConsignees = consigBean.getRecord_list();
            iCount = recordConsignees.size();
        }
        //成功条数
        int suceessCount;
        //映射map
        Map afterCheckMap = null;
        //将推送总量转换为数值
        int count = 0;
        try {
            count = total_pushed_num;
        } catch (NullPointerException e) {
            status = 12;
            LOGGER.error("推送总量前端传入为空，请核实！", e);
            errMsg.append("推送总量前端传入为空，请核实！");
            retMap.put("total_accessed_num", total_pushed_num);
            retMap.put("success_accessed_num", 0);
            retMap.put("status", status);
            retMap.put("errMsg", errMsg.toString());
            return retMap;
        } catch (NumberFormatException e) {
            status = 12;
            LOGGER.error("将推送总量转换为数值出现数据格式转换异常，" +
                    "请核实推送总量是否为合法的数值！非法值为：" + total_pushed_num, e);
            errMsg.append("将推送总量转换为数值出现数据格式转换异常，" +
                    "请核实推送总量是否为合法的数值！非法值为：" + total_pushed_num);
            retMap.put("total_accessed_num", count);
            retMap.put("success_accessed_num", 0);
            retMap.put("status", status);
            retMap.put("errMsg", errMsg.toString());
            return retMap;
        }

        //如果订单记录集合为空，直接返回
        if ((((0 == pushed_data_type)
                || 2 == pushed_data_type)
                && (recordShippers == null
                || recordShippers.size() == 0))
                || (((1 == pushed_data_type)
                || 3 == pushed_data_type)
                && (recordConsignees == null
                || recordConsignees.size() == 0))) {
            status = 12;
            errMsg.append("订单集合为空，请核实订单集合数据！");
            retMap.put("total_accessed_num", count);
            retMap.put("success_accessed_num", 0);
            retMap.put("status", status);
            retMap.put("errMsg", errMsg.toString());
            return retMap;
        }

        //实际值与前端设置的订单总数值不相等，不予推送
        if (((0 == pushed_data_type
                || 2 == pushed_data_type)
                && count != iCount)
                || ((1 == pushed_data_type
                || 3 == pushed_data_type)
                && count != iCount)) {
            status = 13;
            LOGGER.error("推送总量为：" + count + ",但实际集合数据中推送的总量为："
                    + iCount + "，二者不相等..不予推送");
            errMsg.append("推送总量为：" + count + ",但实际集合数据中推送的总量为："
                    + iCount + "，二者不相等..不予推送");
            retMap.put("total_accessed_num", 0);
            retMap.put("success_accessed_num", 0);
            retMap.put("status", status);
            retMap.put("errMsg", errMsg.toString());
            return retMap;
        }

        //检查最外层的每个字段，如果有异常，数据全部返回
        if (0 == pushed_data_type || 2 == pushed_data_type) {
            //LOGGER.info("=====外围信息字段校验之前的数据集合为："+gson.toJson(paramShiper));
            retMap = this.checkEnterpriseData(paramShiper, retMap, pushed_data_type, count);
        } else if (1 == pushed_data_type || 3 == pushed_data_type) {
            retMap = this.checkEnterpriseData(consigBean, retMap, pushed_data_type, count);
            //LOGGER.info("======");
        }
        if (14 == status || 13 == status) {
            return retMap;
        }

        //检查订单子项的各个字段
        if (0 == pushed_data_type || 2 == pushed_data_type) {
            //验证发货订单
            if(recordShippers==null || recordShippers.size()<=0){
                LOGGER.error("=====字段校验之前的数据集合为空=======");
            }
            afterCheckMap = this.getShipper(recordShippers, count, pushed_data_type);
            suceessCount = (Integer) afterCheckMap.get("success_accessed_num");
            if (suceessCount != count) {
                recordShippers = (List<ShipperBean>) afterCheckMap.get("record_list");
                if(recordShippers==null || recordShippers.size()==0){
                    LOGGER.error("=====从发货订单数据中获取的订单集合为空，因为校验不通过");
                }
                LOGGER.info("=========recordShippers的长度为："+ recordShippers.size());
                //将合法的数据重新放入Json对象中
                paramShiper.setRecord_list(recordShippers);
            }
        } else if (1 == pushed_data_type || 3 == pushed_data_type) {
            //验证收货订单
            afterCheckMap = this.getConsignee(recordConsignees, count, pushed_data_type);
            suceessCount = (Integer) afterCheckMap.get("success_accessed_num");
            if (suceessCount != count) {
                recordConsignees = (List<ConsigneeBean>) afterCheckMap.get("record_list");
                //将合法的数据重新放入Json对象中
                consigBean.setRecord_list(recordConsignees);
            }
        }

        retMap.putAll(afterCheckMap);

        //将Json对象转换为Json字符串返回
        String jsonStr = null;
        try {
            if (0 == pushed_data_type || 2 == pushed_data_type) {
                jsonStr = gson.toJson(paramShiper);
                //LOGGER.info("CheckJson校验类接收到的发货订单数据为："+jsonStr);
            } else {
                jsonStr = gson.toJson(consigBean);
                //LOGGER.info("CheckJson校验类接收到的收货订单数据为："+jsonStr);
            }
        } catch (Exception e) {
            //11表示从JavaBean对象转换为json字符串失败
            status = 11;
            LOGGER.error("数据验证类（CheckJson）中：从JavaBean对象转换为json字符串失败！");
            errMsg.append("数据验证类（CheckJson）中：从JavaBean对象转换为json字符串失败！");
        }

        //封装返回
        retMap.put("jsonStr", jsonStr);
        /*System.out.println(jsonStr+"\n"+gson.toJson(recordErrMsg));*/
        retMap.put("status", status);
        retMap.put("errMsg", errMsg.toString());
        retMap.put("recordErrMsg", gson.toJson(recordErrMsg));
        return retMap;
    }

    /**
     * 发货单信息
     *
     * @param record_list 发货单集合
     * @return 针对发货单验证之后数据
     */
    private Map<String, Object> getShipper(List<ShipperBean> record_list, Integer count, Integer dataType) {
        int iCount = count;
        Map map = null;
        Gson gson = new Gson();
        ShipperBean itemBean;
        List<Map> itemList;
        FieldDataRule fieldDataRule = new FieldDataRule();
        boolean flag = false;
        //LOGGER.info("进入getShipper的集合为："+gson.toJson(record_list));
        List<Map> ruleList = new ArrayList<Map>();
        if (recordErrMsg == null) {
            recordErrMsg = new ArrayList<Map>();
        }
        for (int i = iCount - 1; i >= 0; i--) {
            flag = false;
            itemBean = record_list.get(i);
            //验证发货单非空字段
            itemList = this.checkIsNullShipper(itemBean, i, gson, dataType);
            //LOGGER.info("进入checkIsNullShipper的集合为："+itemList==null?"非空校验通过！":String.valueOf(itemList.size()));
            if (itemList.size() > 0) {
                recordErrMsg.addAll(itemList);
                record_list.remove(i);
                iCount--;
                itemList.clear();
                continue;
            }

            /*正式对发货单每一个字段进行规制校验
              寄递单号*/
            if (!fieldDataRule.isNumeric(itemBean.getExpress_number())) {
                map = new HashedMap();
                map.put("seq", i);
                LOGGER.error("寄递单号规则校验不通过！规定必须是数字," +
                        "该集合元素为：" + gson.toJson(itemBean));
                //验证是否为初次
                if (!flag) {
                    status = 9;
                    map.put("detail_info", "寄递单号规则校验不通过！规定必须是数字," +
                            "该集合元素为：" + gson.toJson(itemBean));
                } else {
                    map.put("detail_info", "寄递单号规则校验不通过！规定必须是数字");
                }
                ruleList.add(map);
                flag = true;
            }
            //发货人身份证
            if (StringUtils.isNotBlank(itemBean.getShipper_id_card())
                    && !fieldDataRule.isCharNum(itemBean.getShipper_id_card())) {

                map = new HashedMap();
                map.put("seq", i);
                LOGGER.error("发货人身份证规则校验不通过！规定必须是数字" +
                        "或者数字和字母组合,该集合元素为：" + gson.toJson(itemBean));
                if (!flag) {
                    status = 9;
                    map.put("detail_info", "发货人身份证规则校验不通过！规定必须是数字" +
                            "或者数字和字母组合,该集合元素为：" + gson.toJson(itemBean));
                } else {
                    map.put("detail_info", "发货人身份证规则校验不通过！规定必须是数字" +
                            "或者数字和字母组合");
                }
                ruleList.add(map);
                flag = true;
            }
            //发货人姓名
            if (StringUtils.isNotBlank(itemBean.getShipper_name())
                    && !fieldDataRule.isChinese(itemBean.getShipper_name())) {
                map = new HashedMap();
                map.put("seq", i);
                LOGGER.error("发货人姓名规则校验不通过！规定必须是中文," +
                        "该集合元素为：" + gson.toJson(itemBean));
                //验证是否为初次
                if (!flag) {
                    status = 9;
                    map.put("detail_info", "发货人姓名规则校验不通过！规定必须是中文," +
                            "该集合元素为：" + gson.toJson(itemBean));
                } else {
                    map.put("detail_info", "发货人姓名规则校验不通过！规定必须是中文;");
                }
                ruleList.add(map);
                flag = true;
            }
            //发货人手机号
            if (itemBean.getShipper_phone() != null
                    && !fieldDataRule.isMobileNO(String.valueOf(itemBean.getShipper_phone()))) {
                map = new HashedMap();
                map.put("seq", i);
                LOGGER.error("发货人手机号规则校验不通过！规定合法的手机号码" +
                        ",该集合元素为：" + gson.toJson(itemBean));
                //验证是否为初次
                if (!flag) {
                    status = 9;
                    map.put("detail_info", "发货人手机号规则校验不通过！规定合法的手机号码" +
                            ",该集合元素为：" + gson.toJson(itemBean));
                } else {
                    map.put("detail_info", "发货人手机号规则校验不通过！规定合法的手机号码;");
                }
                ruleList.add(map);
                flag = true;
            }
            //发货地址
            if (StringUtils.isNotBlank(itemBean.getShipper_address())
                    && !fieldDataRule.isCharNumChinese(itemBean.getShipper_address())) {
                map = new HashedMap();
                map.put("seq", i);
                LOGGER.error("发货地址规则校验不通过！规定字符与数字组成" +
                        ",该集合元素为：" + gson.toJson(itemBean));
                //验证是否为初次
                if (!flag) {
                    status = 9;
                    map.put("detail_info", "发货地址规则校验不通过！规定字符与数字组成" +
                            ",该集合元素为：" + gson.toJson(itemBean));
                } else {
                    map.put("detail_info", "发货地址规则校验不通过！规定字符与数字组成;");
                }
                ruleList.add(map);
                flag = true;
            }
            //GPS位置-经度
            if (!fieldDataRule.isSixSiteSimData(String.valueOf(itemBean.getShipper_longitude()))) {
                map = new HashedMap();
                map.put("seq", i);
                LOGGER.error("GPS位置-经度规则校验不通过！规定" +
                        "精确到小数点后6位,该集合元素为：" + gson.toJson(itemBean));
                //验证是否为初次
                if (!flag) {
                    status = 9;
                    map.put("detail_info", "GPS位置-经度规则校验不通过！规定" +
                            "精确到小数点后6位,该集合元素为：" + gson.toJson(itemBean));
                } else {
                    map.put("detail_info", "GPS位置-经度规则校验不通过！规定" +
                            "精确到小数点后6位;");
                }
                ruleList.add(map);
                flag = true;
            }
            //GPS位置-纬度
            if (!fieldDataRule.isSixSiteSimData(String.valueOf(String.valueOf(itemBean.getShipper_latitude())))) {
                map = new HashedMap();
                map.put("seq", i);
                LOGGER.error("GPS位置-纬度规则校验不通过！规定" +
                        "精确到小数点后6位,该集合元素为：" + gson.toJson(itemBean));
                //验证是否为初次
                if (!flag) {
                    status = 9;
                    map.put("detail_info", "GPS位置-纬度规则校验不通过！规定" +
                            "精确到小数点后6位,该集合元素为：" + gson.toJson(itemBean));
                } else {
                    map.put("detail_info", "GPS位置-纬度规则校验不通过！规定" +
                            "精确到小数点后6位;");
                }
                ruleList.add(map);
                flag = true;
            }
            //是否实名
            if (!fieldDataRule.isThreeNum(String.valueOf(itemBean.getShipper_is_realname()))) {
                map = new HashedMap();
                map.put("seq", i);
                LOGGER.error("是否实名规则校验不通过！规定必须是0,1,2中的枚举值" +
                        ",该集合元素为：" + gson.toJson(itemBean));
                //验证是否为初次
                if (!flag) {
                    status = 9;
                    map.put("detail_info", "是否实名规则校验不通过！规定必须是0,1,2中的枚举值" +
                            ",该集合元素为：" + gson.toJson(itemBean));
                } else {
                    map.put("detail_info", "是否实名规则校验不通过！规定必须是0,1,2中的枚举值;");
                }
                ruleList.add(map);
                flag = true;
            }

            //发货人照片
            if (StringUtils.isNotBlank(itemBean.getShipper_photo())
                    && !fieldDataRule.isBase64(itemBean.getShipper_photo())) {
                map = new HashedMap();
                map.put("seq", i);
                LOGGER.error("发货人照片规则校验不通过！规定必须base64编码字符串" +
                        ",该集合元素为：" + gson.toJson(itemBean));
                //验证是否为初次
                if (!flag) {
                    status = 9;
                    map.put("detail_info", "发货人照片规则校验不通过！规定必须base64编码字符串" +
                            ",该集合元素为：" + gson.toJson(itemBean));
                } else {
                    map.put("detail_info", "发货人照片规则校验不通过！规定必须base64编码字符串;");
                }
                ruleList.add(map);
                flag = true;
            }
            //货物照片
            if (StringUtils.isNotBlank(itemBean.getShipper_goods_photo())
                    && !fieldDataRule.isBase64(itemBean.getShipper_goods_photo())) {
                map = new HashedMap();
                map.put("seq", i);
                LOGGER.error("货物照片规则校验不通过！规定合法的手机号码" +
                        ",该集合元素为：" + gson.toJson(itemBean));
                //验证是否为初次
                if (!flag) {
                    status = 9;
                    map.put("detail_info", "货物照片规则校验不通过！规定必须base64编码字符串" +
                            ",该集合元素为：" + gson.toJson(itemBean));
                } else {
                    map.put("detail_info", "货物照片规则校验不通过！规定必须base64编码字符串;");
                }
                ruleList.add(map);
                flag = true;
            }
            //货物名称
            if (StringUtils.isNotBlank(itemBean.getGoods_name())
                    && !fieldDataRule.isChinese(itemBean.getGoods_name())) {
                map = new HashedMap();
                map.put("seq", i);
                LOGGER.error("货物名称规则校验不通过！规定是中文字符" +
                        ",该集合元素为：" + gson.toJson(itemBean));
                //验证是否为初次
                if (!flag) {
                    status = 9;
                    map.put("detail_info", "货物名称规则校验不通过！规定中文字符" +
                            ",该集合元素为：" + gson.toJson(itemBean));
                } else {
                    map.put("detail_info", "货物名称规则校验不通过！规定中文字符;");
                }
                ruleList.add(map);
                flag = true;
            }
            //收货人姓名
            if (StringUtils.isNotBlank(itemBean.getConsignee_name())
                    && !fieldDataRule.isChinese(itemBean.getConsignee_name())) {
                map = new HashedMap();
                map.put("seq", i);
                LOGGER.error("收货人姓名规则校验不通过！规定中文字符" +
                        ",该集合元素为：" + gson.toJson(itemBean));
                //验证是否为初次
                if (!flag) {
                    status = 9;
                    map.put("detail_info", "收货人姓名规则校验不通过！规定中文字符" +
                            ",该集合元素为：" + gson.toJson(itemBean));
                } else {
                    map.put("detail_info", "收货人姓名规则校验不通过！规定中文字符;");
                }
                ruleList.add(map);
                flag = true;
            }
            //收货人电话
            if (itemBean.getConsignee_phone() != null
                    && !fieldDataRule.isMobileNO(String.valueOf(itemBean.getConsignee_phone()))) {
                map = new HashedMap();
                map.put("seq", i);
                LOGGER.error("收货人电话规则校验不通过！规定合法的手机号码" +
                        ",该集合元素为：" + gson.toJson(itemBean));
                //验证是否为初次
                if (!flag) {
                    status = 9;
                    map.put("detail_info", "收货人电话规则校验不通过！规定合法的手机号码" +
                            ",该集合元素为：" + gson.toJson(itemBean));
                } else {
                    map.put("detail_info", "收货人电话规则校验不通过！规定合法的手机号码;");
                }
                ruleList.add(map);
                flag = true;
            }
            //收货地址
            if (StringUtils.isNotBlank(itemBean.getConsignee_address())
                    && !fieldDataRule.isCharNumChinese(itemBean.getConsignee_address())) {
                map = new HashedMap();
                map.put("seq", i);
                LOGGER.error("收货地址规则校验不通过！规定字符与数字组成" +
                        ",该集合元素为：" + gson.toJson(itemBean));
                //验证是否为初次
                if (!flag) {
                    status = 9;
                    map.put("detail_info", "收货地址规则校验不通过！规定字符与数字组成" +
                            ",该集合元素为：" + gson.toJson(itemBean));
                } else {
                    map.put("detail_info", "收货地址规则校验不通过！规定字符与数字组成;");
                }
                ruleList.add(map);
                flag = true;
            }
            //接单员编号
            if (StringUtils.isNotBlank(itemBean.getReceiver_id())
                    && !fieldDataRule.isCharNum(itemBean.getReceiver_id())) {
                map = new HashedMap();
                map.put("seq", i);
                LOGGER.error("接单员编号规则校验不通过！规定为数字或者数字与字符组成" +
                        ",该集合元素为：" + gson.toJson(itemBean));
                //验证是否为初次
                if (!flag) {
                    status = 9;
                    map.put("detail_info", "接单员编号规则校验不通过！规定为数字或者数字与字符组成" +
                            ",该集合元素为：" + gson.toJson(itemBean));
                } else {
                    map.put("detail_info", "接单员编号规则校验不通过！规定为数字或者数字与字符组成;");
                }
                ruleList.add(map);
                flag = true;
            }

            //嫌疑标记
            if (!fieldDataRule.isNumeric(String.valueOf(itemBean.getShipper_tag()))) {
                map = new HashedMap();
                map.put("seq", i);
                LOGGER.error("嫌疑标记规则校验不通过！规定为数字组成" +
                        ",该集合元素为：" + gson.toJson(itemBean));
                //验证是否为初次
                if (!flag) {
                    status = 9;
                    map.put("detail_info", "嫌疑标记规则校验不通过！规定为数字组成" +
                            ",该集合元素为：" + gson.toJson(itemBean));
                } else {
                    map.put("detail_info", "嫌疑标记规则校验不通过！规定为数字组成;");
                }
                ruleList.add(map);
                flag = true;
            }
            //地区编号
            if (!fieldDataRule.isSixNum(String.valueOf(itemBean.getShipment_area_number()))) {
                map = new HashedMap();
                map.put("seq", i);
                LOGGER.error("发货地区编号规则校验不通过！规定为六位数字组成" +
                        ",该集合元素为：" + gson.toJson(itemBean));
                //验证是否为初次
                if (!flag) {
                    status = 9;
                    map.put("detail_info", "发货地区编号规则校验不通过！规定为六位数字组成" +
                            ",该集合元素为：" + gson.toJson(itemBean));
                } else {
                    map.put("detail_info", "发货地区编号规则校验不通过！规定为六位数字组成;");
                }
                ruleList.add(map);
                flag = true;
            }
            if (flag == true || ruleList.size() > 0) {
                iCount--;
                recordErrMsg.addAll(ruleList);
                record_list.remove(i);
                ruleList = new ArrayList<Map>();
            }
        }
        //LOGGER.info("getShipper方法校验之后的集合为："+record_list==null?"为空":gson.toJson(record_list));
        //LOGGER.info("getShipper方法校验之后的recordErrMsg为："+recordErrMsg==null?"recordErrMsg为空":gson.toJson(recordErrMsg));

        //封装返回
        Map<String, Object> retMap = new HashMap();
        retMap.put("total_accessed_num", count);
        retMap.put("success_accessed_num", iCount);
        retMap.put("record_list", record_list);
        return retMap;
    }

    /**
     * 收货单验证方法
     *
     * @param record_list 收货单集合
     * @return 收货单验证之后的数据
     */
    private Map<String, Object> getConsignee(List<ConsigneeBean> record_list, Integer count, Integer dataType) {
        //定义并初始化验证之前默认的成功推送条数
        int iCount = count;
        //定义临时变量，用作map与发货单javaBean对象的转型
        ConsigneeBean itemBean;
        Map map = null;
        FieldDataRule fieldDataRule = new FieldDataRule();
        List<Map> consigneeList;
        List<Map> ruleList = new ArrayList<Map>();
        Gson gson = new Gson();
        boolean flag = false;
        if (recordErrMsg == null) {
            recordErrMsg = new ArrayList<Map>();
        }
        for (int i = iCount - 1; i >= 0; i--) {
            itemBean = record_list.get(i);
            consigneeList = this.checkIsNullConsignee(itemBean, i, gson, dataType);
            if (consigneeList.size() > 0) {
                recordErrMsg.addAll(consigneeList);
                record_list.remove(i);
                iCount--;
                continue;
            }

            /*正式对收货单每一个字段进行规制校验
              寄递单号*/
            if (!fieldDataRule.isNumeric(itemBean.getExpress_number())) {
                map = new HashedMap();
                map.put("seq", i);
                LOGGER.error("寄递单号规则校验不通过！规定必须是数字," +
                        "该集合元素为：" + gson.toJson(itemBean));
                //验证是否为初次
                if (!flag) {
                    status = 9;
                    map.put("detail_info", "寄递单号规则校验不通过！规定必须是数字," +
                            "该集合元素为：" + gson.toJson(itemBean));
                } else {
                    map.put("detail_info", "寄递单号规则校验不通过！规定必须是数字;");
                }
                ruleList.add(map);
                flag = true;
            }
            //发货人身份证
            if (StringUtils.isNotBlank(itemBean.getConsignee_id_card())
                    && !fieldDataRule.isCharNum(itemBean.getConsignee_id_card())) {

                map = new HashedMap();
                map.put("seq", i);
                LOGGER.error("收货人身份证规则校验不通过！规定必须是数字" +
                        "或者数字和字母组合,该集合元素为：" + gson.toJson(itemBean));
                if (!flag) {
                    status = 9;
                    map.put("detail_info", "收货人身份证规则校验不通过！规定必须是数字" +
                            "或者数字和字母组合,该集合元素为：" + gson.toJson(itemBean));
                } else {
                    map.put("detail_info", "收货人身份证规则校验不通过！规定必须是数字" +
                            "或者数字和字母组合;");
                }
                ruleList.add(map);
                flag = true;
            }
            //发货人姓名
            if (StringUtils.isNotBlank(itemBean.getConsignee_name())
                    && !fieldDataRule.isChinese(itemBean.getConsignee_name())) {
                map = new HashedMap();
                map.put("seq", i);
                LOGGER.error("收货人姓名规则校验不通过！规定必须是中文" +
                        "该集合元素为：" + gson.toJson(itemBean));
                //验证是否为初次
                if (!flag) {
                    status = 9;
                    map.put("detail_info", "收货人姓名规则校验不通过！规定必须是中文" +
                            "该集合元素为：" + gson.toJson(itemBean));
                } else {
                    map.put("detail_info", "收货人姓名规则校验不通过！规定必须是中文;");
                }
                ruleList.add(map);
                flag = true;
            }
            //发货人手机号
            if (itemBean.getConsignee_phone() != null
                    && !fieldDataRule.isMobileNO(String.valueOf(itemBean.getConsignee_phone()))) {
                map = new HashedMap();
                map.put("seq", i);
                LOGGER.error("收货人手机号规则校验不通过！规定合法的手机号码" +
                        ",该集合元素为：" + gson.toJson(itemBean));
                //验证是否为初次
                if (!flag) {
                    status = 9;
                    map.put("detail_info", "收货人手机号规则校验不通过！规定合法的手机号码" +
                            ",该集合元素为：" + gson.toJson(itemBean));
                } else {
                    map.put("detail_info", "收货人手机号规则校验不通过！规定合法的手机号码;");
                }
                ruleList.add(map);
                flag = true;
            }
            //收货地址
            if (StringUtils.isNotBlank(itemBean.getConsignee_address())
                    && !fieldDataRule.isCharNumChinese(itemBean.getConsignee_address())) {
                map = new HashedMap();
                map.put("seq", i);
                LOGGER.error("收货地址规则校验不通过！规定中文字符" +
                        ",该集合元素为：" + gson.toJson(itemBean));
                //验证是否为初次
                if (!flag) {
                    status = 9;
                    map.put("detail_info", "收货地址规则校验不通过！规定中文字符" +
                            ",该集合元素为：" + gson.toJson(itemBean));
                } else {
                    map.put("detail_info", "收货地址规则校验不通过！规定中文字符");
                }
                ruleList.add(map);
                flag = true;
            }
            //GPS位置-经度
            if (!fieldDataRule.isSixSiteSimData(String.valueOf(itemBean.getConsignee_longitude()))) {
                map = new HashedMap();
                map.put("seq", i);
                LOGGER.error("收货GPS位置-经度规则校验不通过！规定" +
                        "精确到小数点后6位,该集合元素为：" + gson.toJson(itemBean));
                //验证是否为初次
                if (!flag) {
                    status = 9;
                    map.put("detail_info", "收货GPS位置-经度规则校验不通过！规定" +
                            "精确到小数点后6位,该集合元素为：" + gson.toJson(itemBean));
                } else {
                    map.put("detail_info", "收货GPS位置-经度规则校验不通过！规定" +
                            "精确到小数点后6位");
                }
                ruleList.add(map);
                flag = true;
            }
            //GPS位置-纬度
            if (!fieldDataRule.isSixSiteSimData(String.valueOf(itemBean.getConsignee_latitude()))) {
                map = new HashedMap();
                map.put("seq", i);
                LOGGER.error("收货GPS位置-纬度规则校验不通过！规定" +
                        "精确到小数点后6位,该集合元素为：" + gson.toJson(itemBean));
                //验证是否为初次
                if (!flag) {
                    status = 9;
                    map.put("detail_info", "收货GPS位置-纬度规则校验不通过！规定" +
                            "精确到小数点后6位,该集合元素为：" + gson.toJson(itemBean));
                } else {
                    map.put("detail_info", "收货GPS位置-纬度规则校验不通过！规定" +
                            "精确到小数点后6位");
                }
                ruleList.add(map);
                flag = true;
            }
            //是否实名
            if (!fieldDataRule.isThreeNum(String.valueOf(itemBean.getConsignee_is_realname()))) {
                map = new HashedMap();
                map.put("seq", i);
                LOGGER.error("收货是否实名规则校验不通过！规定必须是0,1,2中的枚举值" +
                        ",该集合元素为：" + gson.toJson(itemBean));
                //验证是否为初次
                if (!flag) {
                    status = 9;
                    map.put("detail_info", "收货是否实名规则校验不通过！规定必须是0,1,2中的枚举值" +
                            ",该集合元素为：" + gson.toJson(itemBean));
                } else {
                    map.put("detail_info", "收货是否实名规则校验不通过！规定必须是0,1,2中的枚举值");
                }
                ruleList.add(map);
                flag = true;
            }
            //发货日期
            if (itemBean.getReceipt_date() == null
                    || itemBean.getReceipt_date() <= 0) {
                map = new HashedMap();
                map.put("seq", i);
                LOGGER.error("收货日期规则校验不通过！规定必须是毫秒的时间戳（整数）" +
                        ",该集合元素为：" + gson.toJson(itemBean));
                //验证是否为初次
                if (!flag) {
                    status = 9;
                    map.put("detail_info", "收货日期规则校验不通过！规定必须是毫秒的时间戳（整数）" +
                            ",该集合元素为：" + gson.toJson(itemBean));
                } else {
                    map.put("detail_info", "收货日期规则校验不通过！规定必须是毫秒的时间戳（整数）");
                }
                ruleList.add(map);
                flag = true;
            }
            //收货人电话
            if (itemBean.getConsignee_phone() != null
                    && !fieldDataRule.isBase64(String.valueOf(itemBean.getConsignee_phone()))) {
                map = new HashedMap();
                map.put("seq", i);
                LOGGER.error("收货人照片规则校验不通过！规定必须base64编码字符串" +
                        ",该集合元素为：" + gson.toJson(itemBean));
                //验证是否为初次
                if (!flag) {
                    status = 9;
                    map.put("detail_info", "收货人照片规则校验不通过！规定必须base64编码字符串" +
                            ",该集合元素为：" + gson.toJson(itemBean));
                } else {
                    map.put("detail_info", "收货人照片规则校验不通过！规定必须base64编码字符串");
                }
                ruleList.add(map);
                flag = true;
            }
            //货物照片
            if (StringUtils.isNotBlank(itemBean.getConsignee_goods_photo())
                    && !fieldDataRule.isBase64(itemBean.getConsignee_goods_photo())) {
                map = new HashedMap();
                map.put("seq", i);
                LOGGER.error("收货货物照片规则校验不通过！规定合法的手机号码" +
                        ",该集合元素为：" + gson.toJson(itemBean));
                //验证是否为初次
                if (!flag) {
                    status = 9;
                    map.put("detail_info", "收货货物照片规则校验不通过！规定必须base64编码字符串" +
                            ",该集合元素为：" + gson.toJson(itemBean));
                } else {
                    map.put("detail_info", "收货货物照片规则校验不通过！规定必须base64编码字符串");
                }
                ruleList.add(map);
                flag = true;
            }
            //货物名称
            if (StringUtils.isNotBlank(itemBean.getGoods_name())
                    && !fieldDataRule.isChinese(itemBean.getGoods_name())) {
                map = new HashedMap();
                map.put("seq", i);
                LOGGER.error("收货货物名称规则校验不通过！规定是中文字符" +
                        ",该集合元素为：" + gson.toJson(itemBean));
                //验证是否为初次
                if (!flag) {
                    status = 9;
                    map.put("detail_info", "收货货物名称规则校验不通过！规定中文字符" +
                            ",该集合元素为：" + gson.toJson(itemBean));
                } else {
                    map.put("detail_info", "收货货物名称规则校验不通过！规定中文字符");
                }
                ruleList.add(map);
                flag = true;
            }
            //发货人姓名
            if (StringUtils.isNotBlank(itemBean.getShipper_name())
                    && !fieldDataRule.isChinese(itemBean.getConsignee_name())) {
                map = new HashedMap();
                map.put("seq", i);
                LOGGER.error("发货人姓名规则校验不通过！规定中文字符" +
                        ",该集合元素为：" + gson.toJson(itemBean));
                //验证是否为初次
                if (!flag) {
                    status = 9;
                    map.put("detail_info", "发货人姓名规则校验不通过！规定中文字符" +
                            ",该集合元素为：" + gson.toJson(itemBean));
                } else {
                    map.put("detail_info", "发货人姓名规则校验不通过！规定中文字符");
                }
                ruleList.add(map);
                flag = true;
            }
            //发货人电话
            if (itemBean.getShipper_phone() != null
                    && !fieldDataRule.isMobileNO(String.valueOf(itemBean.getShipper_phone()))) {
                map = new HashedMap();
                map.put("seq", i);
                LOGGER.error("发货人电话规则校验不通过！规定合法的手机号码" +
                        ",该集合元素为：" + gson.toJson(itemBean));
                //验证是否为初次
                if (!flag) {
                    status = 9;
                    map.put("detail_info", "发货人电话规则校验不通过！规定合法的手机号码" +
                            ",该集合元素为：" + gson.toJson(itemBean));
                } else {
                    map.put("detail_info", "发货人电话规则校验不通过！规定合法的手机号码");
                }
                ruleList.add(map);
                flag = true;
            }
            //发货地址
            if (StringUtils.isNotBlank(itemBean.getShipper_address())
                    && !fieldDataRule.isCharNumChinese(itemBean.getShipper_address())) {
                map = new HashedMap();
                map.put("seq", i);
                LOGGER.error("发货地址规则校验不通过！规定中文字符" +
                        ",该集合元素为：" + gson.toJson(itemBean));
                //验证是否为初次
                if (!flag) {
                    status = 9;
                    map.put("detail_info", "发货地址规则校验不通过！规定中文字符" +
                            ",该集合元素为：" + gson.toJson(itemBean));
                } else {
                    map.put("detail_info", "发货地址规则校验不通过！规定中文字符");
                }
                ruleList.add(map);
                flag = true;
            }
            //派送员编号
            if (StringUtils.isNotBlank(itemBean.getDeliver_id())
                    && !fieldDataRule.isCharNum(itemBean.getDeliver_id())) {
                map = new HashedMap();
                map.put("seq", i);
                LOGGER.error("派送员编号规则校验不通过！规定为数字或者数字与字符组成" +
                        ",该集合元素为：" + gson.toJson(itemBean));
                //验证是否为初次
                if (!flag) {
                    status = 9;
                    map.put("detail_info", "派送员编号规则校验不通过！规定为数字或者数字与字符组成" +
                            ",该集合元素为：" + gson.toJson(itemBean));
                } else {
                    map.put("detail_info", "派送员编号规则校验不通过！规定为数字或者数字与字符组成");
                }
                ruleList.add(map);
                flag = true;
            }

            //嫌疑标记
            if (!fieldDataRule.isNumeric(String.valueOf(itemBean.getConsignee_tag()))) {
                map = new HashedMap();
                map.put("seq", i);
                LOGGER.error("收货嫌疑标记规则校验不通过！规定为数字组成" +
                        ",该集合元素为：" + gson.toJson(itemBean));
                //验证是否为初次
                if (!flag) {
                    status = 9;
                    map.put("detail_info", "嫌疑标记规则校验不通过！规定为数字组成" +
                            ",该集合元素为：" + gson.toJson(itemBean));
                } else {
                    map.put("detail_info", "嫌疑标记规则校验不通过！规定为数字组成");
                }
                ruleList.add(map);
                flag = true;
            }
            //地区编号
            if (!fieldDataRule.isSixNum(String.valueOf(itemBean.getReceipt_area_number()))) {
                map = new HashedMap();
                map.put("seq", i);
                LOGGER.error("收货地区编号规则校验不通过！规定为六位数字组成" +
                        ",该集合元素为：" + gson.toJson(itemBean));
                //验证是否为初次
                if (!flag) {
                    status = 9;
                    map.put("detail_info", "地区编号规则校验不通过！规定为六位数字组成" +
                            ",该集合元素为：" + gson.toJson(itemBean));
                } else {
                    map.put("detail_info", "地区编号规则校验不通过！规定为六位数字组成");
                }
                ruleList.add(map);
                flag = true;
            }
            if (ruleList.size() > 0) {
                iCount--;
                recordErrMsg.addAll(ruleList);
                record_list.remove(i);
                ruleList = new ArrayList<Map>();
            }
        }

        Map<String, Object> retMap = new HashMap();
        retMap.put("total_accessed_num", count);
        retMap.put("success_accessed_num", iCount);
        retMap.put("recordErrMsg", recordErrMsg);
        retMap.put("record_list", record_list);
        return retMap;
    }

    /**
     * 校验最外层发货单的元数据
     *
     * @param param    收发货单最外层Bean
     * @param retMap   异常信息
     * @param dataType 数据类型
     * @return 异常信息
     */
    private Map<String, Object> checkEnterpriseData(Object param, Map retMap, Integer dataType, int count) {
        //检查最外层的非空校验
        this.checkIsNullEnterpriseField(param, dataType);
        ShipperEnterpriseBean shipperParam;
        ConsigneeEnterpriseBean consigneeParam;
        if (0 == dataType || 2 == dataType) {
            shipperParam = (ShipperEnterpriseBean) param;
            retMap.put("total_accessed_num", shipperParam.getTotal_pushed_num());
            //推送时间
            if (shipperParam.getPushed_data_time() == null || shipperParam.getPushed_data_time() <= 0) {
                status = 14;
                errMsg.append("推送时间规则校验不通过!规定只能用毫秒的时间戳表示(整数)!");
            }
            //企业类型
            if (shipperParam.getEnterprise_type() == null || shipperParam.getEnterprise_type() < 0) {
                status = 14;
                errMsg.append("企业类型规则校验不通过!规定只能用数字");
            }
        } else {
            consigneeParam = (ConsigneeEnterpriseBean) param;
            retMap.put("total_accessed_num", consigneeParam.getTotal_pushed_num());
            //推送时间
            if (consigneeParam.getPushed_data_time() == null || consigneeParam.getPushed_data_time() <= 0) {
                status = 14;
                errMsg.append("推送时间规则校验不通过!规定只能用毫秒的时间戳表示(整数)!");
            }
            //企业类型
            if (consigneeParam.getEnterprise_type() == null || consigneeParam.getEnterprise_type() < 0) {
                status = 14;
                errMsg.append("企业类型规则校验不通过!规定只能用数字");
            }
        }
        if (status == 14) {
            retMap.put("total_accessed_num", count);
            retMap.put("success_accessed_num", 0);
            retMap.put("errMsg", errMsg.toString());
            return retMap;
        }

        return retMap;
    }

    /**
     * 对收发货单的企业数据每个字段非空校验
     */
    private void checkIsNullEnterpriseField(Object enterpriseBean, Integer dataType) {
        errMsg = new StringBuffer();
        status = 14;
        ShipperEnterpriseBean shipperEnterpriseBean;
        ConsigneeEnterpriseBean consigneeEnterpriseBean;
        Long pushed_data_time = null;
        Integer enterprise_type = null;
        String enterprise_id = null;
        String subbranch_id = null;
        if (0 == dataType || 2 == dataType) {
            shipperEnterpriseBean = (ShipperEnterpriseBean) enterpriseBean;
            pushed_data_time = shipperEnterpriseBean.getPushed_data_time();
            enterprise_type = shipperEnterpriseBean.getEnterprise_type();
            enterprise_id = shipperEnterpriseBean.getEnterprise_id();
            subbranch_id = shipperEnterpriseBean.getSubbranch_id();
        } else if (1 == dataType || 3 == dataType) {
            consigneeEnterpriseBean = (ConsigneeEnterpriseBean) enterpriseBean;
            pushed_data_time = consigneeEnterpriseBean.getPushed_data_time();
            enterprise_type = consigneeEnterpriseBean.getEnterprise_type();
            enterprise_id = consigneeEnterpriseBean.getEnterprise_id();
            subbranch_id = consigneeEnterpriseBean.getSubbranch_id();
        } else{
            LOGGER.error("非法的数据推送类型："+dataType);
        }
        //企业编号
        if (StringUtils.isBlank(enterprise_id)) {
            errMsg.append("企业信息中企业编号必须填写;");
        }
        //地区编号
        if (StringUtils.isBlank(subbranch_id)) {
            errMsg.append("企业信息中网点编号必须填写;");
        }
        //推送时间
        if (pushed_data_time == null || pushed_data_time <= 0) {
            errMsg.append("企业信息中推送时间必须填写;");
        }

        if (enterprise_type == null || enterprise_type < 0) {
            errMsg.append("企业信息中企业类型必须填写;");
        }
        if (StringUtils.isBlank(errMsg.toString())) {
            status = 0;
        }
    }

    /**
     * 检查发货单的字段非空情况
     *
     * @param itemBean
     */
    private List<Map> checkIsNullShipper(ShipperBean itemBean, int i, Gson gson, Integer dataType) {
        Map map = null;
        boolean flag = false;
        List<Map> list = new ArrayList<Map>();
        if (2 == dataType && (itemBean.getShipper_update_time() == null || itemBean.getShipper_update_time() <= 0L)) {
            map = new HashMap();
            map.put("seq", i);
            LOGGER.error("该发货更新订单中发货修改日期字段不能为空！因此该发货修改订单" +
                    "验证不通过！不能传送,该发货修改订单为：" + gson.toJson(itemBean));
            if (!flag) {
                map.put("detail_info", "该发货更新订单中发货修改日期字段不能为空！因此该发货修改订单" +
                        "验证不通过！不能传送,该发货修改订单为：" + gson.toJson(itemBean));
            } else {
                map.put("detail_info", "该发货更新订单中发货修改日期字段不能为空！因此该发货修改订单" +
                        "验证不通过！不能传送");
            }
            list.add(map);
        }
        //寄递单号
        if (StringUtils.isBlank(itemBean.getExpress_number())) {
            map = new HashMap();
            LOGGER.error("该发货订单中寄递单号字段不能为空！因此该发货单" +
                    "验证不通过！不能传送,该发货单为：" + gson.toJson(itemBean));
            map.put("seq", i);
            if (!flag) {
                map.put("detail_info", "该发货订单中寄递单号字段不能为空！因此该发货单" +
                        "验证不通过！不能传送,该发货单为：" + gson.toJson(itemBean));
            } else {
                map.put("detail_info", "该发货订单中寄递单号字段不能为空！因此该发货单" +
                        "验证不通过！不能传送");
            }

            list.add(map);
        }
        //GPS位置-经度
        if (StringUtils.isBlank(String.valueOf(itemBean.getShipper_longitude()))) {
            map = new HashMap();
            map.put("seq", i);
            LOGGER.error("该发货订单中GPS位置-经度字段不能为空！因此该发货单" +
                    "验证不通过！不能传送,该发货单为：" + gson.toJson(itemBean));
            if (!flag) {
                map.put("detail_info", "该发货订单中GPS位置-经度字段不能为空！因此该发货单" +
                        "验证不通过！不能传送,该发货单为：" + gson.toJson(itemBean));
            } else {
                map.put("detail_info", "该发货订单中GPS位置-经度字段不能为空！因此该发货单" +
                        "验证不通过！不能传送");
            }

            list.add(map);
        }
        //GPS位置-纬度
        if (StringUtils.isBlank(String.valueOf(itemBean.getShipper_is_realname()))) {
            map = new HashMap();
            map.put("seq", i);
            LOGGER.error("该发货订单中GPS位置-纬度字段不能为空！因此该发货单" +
                    "验证不通过！不能传送,该发货单为：" + gson.toJson(itemBean));
            if (!flag) {
                map.put("detail_info", "该发货订单中GPS位置-纬度字段不能为空！因此该发货单" +
                        "验证不通过！不能传送,该发货单为：" + gson.toJson(itemBean));
            } else {
                map.put("detail_info", "该发货订单中GPS位置-纬度字段不能为空！因此该发货单" +
                        "验证不通过！不能传送");
            }
            list.add(map);
        }
        //是否实名
        if (StringUtils.isBlank(String.valueOf(itemBean.getShipper_is_realname()))) {
            map = new HashMap();
            map.put("seq", i);
            LOGGER.error("该发货订单中是否实名字段不能为空！因此该发货单" +
                    "验证不通过！不能传送,该发货单为：" + gson.toJson(itemBean));
            if (!flag) {
                map.put("detail_info", "该发货订单中是否实名字段不能为空！因此该发货单" +
                        "验证不通过！不能传送,该发货单为：" + gson.toJson(itemBean));
            } else {
                map.put("detail_info", "该发货订单中是否实名字段不能为空！因此该发货单" +
                        "验证不通过！不能传送");
            }

            list.add(map);
        }
        //发货日期
        if (itemBean.getShipment_date() == null || itemBean.getShipment_date() <= 0) {
            map = new HashMap();
            map.put("seq", i);
            LOGGER.error("该发货订单中发货日期字段不能为空！因此该发货单" +
                    "验证不通过！不能传送,该发货单为：" + gson.toJson(itemBean));
            if (!flag) {
                map.put("detail_info", "该发货订单中发货日期字段不能为空！因此该发货单" +
                        "验证不通过！不能传送,该发货单为：" + gson.toJson(itemBean));
            } else {
                map.put("detail_info", "该发货订单中发货日期字段不能为空！因此该发货单" +
                        "验证不通过！不能传送");
            }

            list.add(map);
        }
        //接单员编号
        if (StringUtils.isBlank(itemBean.getReceiver_id())) {
            map = new HashMap();
            map.put("seq", i);
            LOGGER.error("该发货订单中接单员编号字段不能为空！因此该发货单" +
                    "验证不通过！不能传送,该发货单为：" + gson.toJson(itemBean));
            if (!flag) {
                map.put("detail_info", "该发货订单中接单员编号字段不能为空！因此该发货单" +
                        "验证不通过！不能传送,该发货单为：" + gson.toJson(itemBean));
            } else {
                map.put("detail_info", "该发货订单中接单员编号字段不能为空！因此该发货单" +
                        "验证不通过！不能传送");
            }

            list.add(map);
        }
        //嫌疑标记
        if (StringUtils.isBlank(String.valueOf(itemBean.getShipper_tag()))) {
            map = new HashMap();
            map.put("seq", i);
            LOGGER.error("该发货订单中嫌疑标记字段不能为空！因此该发货单" +
                    "验证不通过！不能传送,该发货单为：" + gson.toJson(itemBean));
            if (!flag) {
                map.put("detail_info", "该发货订单中嫌疑标记字段不能为空！因此该发货单" +
                        "验证不通过！不能传送,该发货单为：" + gson.toJson(itemBean));
            } else {
                map.put("detail_info", "该发货订单中嫌疑标记字段不能为空！因此该发货单" +
                        "验证不通过！不能传送");
            }

            list.add(map);
        }
        //地区编号
        if (StringUtils.isBlank(String.valueOf(itemBean.getShipment_area_number()))) {
            map = new HashMap();
            map.put("seq", i);
            LOGGER.error("该发货订单中发货网点地区编号字段不能为空！因此该发货单" +
                    "验证不通过！不能传送,该发货单为：" + gson.toJson(itemBean));
            if (!flag) {
                map.put("detail_info", "该发货订单中发货网点地区编号字段不能为空！因此该发货单" +
                        "验证不通过！不能传送,该发货单为：" + gson.toJson(itemBean));
            } else {
                map.put("detail_info", "该发货订单中发货网点地区编号字段不能为空！因此该发货单" +
                        "验证不通过！不能传送");
            }
            list.add(map);
        }

        //如果原来状态为0，发现非空校验不通过的选项，赋予状态值9
        if (list.size() > 0 && status == 0) {
            status = 9;
        }
        return list;
    }

    /**
     * 校验收货单字段信息
     *
     * @param itemBean 收货单Bean
     * @param i        位置
     * @param gson     Gson解析类
     * @return 验证信息
     */
    private List<Map> checkIsNullConsignee(ConsigneeBean itemBean, int i, Gson gson, Integer dataType) {
        Map map = null;
        boolean flag = false;
        List<Map> list = new ArrayList<Map>();
        if (3 == dataType && (itemBean.getConsignee_update_time() == null
                || itemBean.getConsignee_update_time() <= 0)) {
            map = new HashMap();
            map.put("seq", i);
            if (!flag) {
                map.put("detail_info", "该收货修改订单中修改时间字段不能为空！因此该收货修改订单" +
                        "验证不通过！不能传送,该收货单为：" + gson.toJson(itemBean));
            } else {
                map.put("detail_info", "该收货修改订单中修改时间字段不能为空！因此该收货修改订单" +
                        "验证不通过！不能传送");
            }
            list.add(map);
        }
        //寄递单号
        if (StringUtils.isBlank(itemBean.getExpress_number())) {
            map = new HashMap();
            map.put("seq", i);
            if (!flag) {
                map.put("detail_info", "该收货订单中寄递单号字段不能为空！因此该收货单" +
                        "验证不通过！不能传送,该收货单为：" + gson.toJson(itemBean));
            } else {
                map.put("detail_info", "该收货订单中寄递单号字段不能为空！因此该收货单" +
                        "验证不通过！不能传送");
            }

            list.add(map);
        }
        //GPS位置-经度
        if (StringUtils.isBlank(String.valueOf(itemBean.getConsignee_longitude()))) {
            map = new HashMap();
            map.put("seq", i);
            if (!flag) {
                map.put("detail_info", "该收货订单中GPS位置-经度字段不能为空！因此该收货单" +
                        "验证不通过！不能传送,该收货单为：" + gson.toJson(itemBean));
            } else {
                map.put("detail_info", "该收货订单中GPS位置-经度字段不能为空！因此该收货单" +
                        "验证不通过！不能传送");
            }
            list.add(map);
        }
        //GPS位置-纬度
        if (StringUtils.isBlank(String.valueOf(itemBean.getConsignee_latitude()))) {
            map = new HashMap();
            map.put("seq", i);
            if (!flag) {
                map.put("detail_info", "该收货订单中GPS位置-纬度字段不能为空！因此该收货单" +
                        "验证不通过！不能传送,该收货单为：" + gson.toJson(itemBean));
            } else {
                map.put("detail_info", "该收货订单中GPS位置-纬度字段不能为空！因此该收货单" +
                        "验证不通过！不能传送");
            }

            list.add(map);
        }
        //是否实名
        if (StringUtils.isBlank(String.valueOf(itemBean.getConsignee_is_realname()))) {
            map = new HashMap();
            map.put("seq", i);
            if (!flag) {
                map.put("detail_info", "该收货订单中是否实名字段不能为空！因此该收货单" +
                        "验证不通过！不能传送,该收货单为：" + gson.toJson(itemBean));
            } else {
                map.put("detail_info", "该收货订单中是否实名字段不能为空！因此该收货单" +
                        "验证不通过！不能传送");
            }

            list.add(map);
        }
        //收货日期
        if (itemBean.getReceipt_date() == null || itemBean.getReceipt_date() <= 0) {
            map = new HashMap();
            map.put("seq", i);
            if (!flag) {
                map.put("detail_info", "该收货订单中收货日期字段不能为空！因此该收货单" +
                        "验证不通过！不能传送,该收货单为：" + gson.toJson(itemBean));
            } else {
                map.put("detail_info", "该收货订单中收货日期字段不能为空！因此该收货单" +
                        "验证不通过！不能传送");
            }

            list.add(map);
        }
        //派送员身份证
        if (StringUtils.isBlank(itemBean.getDeliver_id())) {
            map = new HashMap();
            map.put("seq", i);
            if (!flag) {
                map.put("detail_info", "该收货订单中派送员身份证字段不能为空！因此该收货单" +
                        "验证不通过！不能传送,该收货单为：" + gson.toJson(itemBean));
            } else {
                map.put("detail_info", "该收货订单中派送员身份证字段不能为空！因此该收货单" +
                        "验证不通过！不能传送");
            }

            list.add(map);
        }
        //嫌疑标记
        if (StringUtils.isBlank(String.valueOf(itemBean.getConsignee_tag()))) {
            map = new HashMap();
            map.put("seq", i);
            if (!flag) {
                map.put("detail_info", "该收货订单中嫌疑标记字段不能为空！因此该收货单" +
                        "验证不通过！不能传送,该收货单为：" + gson.toJson(itemBean));
            } else {
                map.put("detail_info", "该收货订单中嫌疑标记字段不能为空！因此该收货单" +
                        "验证不通过！不能传送");
            }

            list.add(map);
        }
        //地区编号
        if (itemBean.getReceipt_area_number() == null || StringUtils.isBlank(String.valueOf(itemBean.getReceipt_area_number()))) {
            map = new HashMap();
            map.put("seq", i);
            if (!flag) {
                map.put("detail_info", "该收货订单中网点地区编号字段不能为空！因此该收货单" +
                        "验证不通过！不能传送,该收货单为：" + gson.toJson(itemBean));
            } else {
                map.put("detail_info", "该收货订单中网点地区编号字段不能为空！因此该收货单" +
                        "验证不通过！不能传送");
            }
            list.add(map);
        }
        if (list.size() > 0 && status == 0) {
            status = 9;
        }
        return list;
    }

   /* public static void main(String[] args) {
        String jsonStr = "{\n" +
                "  \"pushed_data_time\":\"1234567890\",\n" +
                "  \"pushed_data_type\":\"0\",\n" +
                "  \"enterprise_type\":\"0\",\n" +
                "  \"enterprise_id\":\"0000001\",\n" +
                "  \"subbranch_id\":\"00001\",\n" +
                "  \"subbranch_area_number\":\"100001\",\n" +
                "  \"total_pushed_num\":\"2\",\n" +
                "  \"record_list\": [\n" +
                "    {\n" +
                "      \"express_number\": \"1\",\n" +
                "      \"shipper_id_card\": \"1111111111111X\",\n" +
                "      \"shipper_name\": \"王一\",\n" +
                "      \"shipper_phone\": \"18111210098\",\n" +
                "      \"shipper_address\": \"资阳市雁江区好好家园小区\",\n" +
                "      \"shipper_longitude\": \"104.062279\",\n" +
                "      \"shipper_latitude\": \"30.572675\",\n" +
                "      \"shipper_is_realname\": \"0\",\n" +
                "      \"shipment_date\": \"111111111\",\n" +
                "      \"shipper_photo\": \"mZkc2YKNDewqeNDMyNDMyNDMyNDMyNA\",\n" +
                "      \"shipper_goods_photo\": \"mZkc2YKNDewqeNDMyNDMyNDMyNDMyNA\",\n" +
                "      \"goods_name\": \"水果提子\",\n" +
                "      \"consignee_name\": \"小李\",\n" +
                "      \"consignee_phone\": \"18233109867\",\n" +
                "      \"consignee_address\": \"成都市新都区你妹区\",\n" +
                "      \"receiver_id\": \"10000\",\n" +
                "      \"shipment_area_number\":\"100001\",\n" +
                "      \"shipper_tag\": \"1\"\n" +
                "    },\n" +
                "    {\n" +
                "      \"express_number\": \"2\",\n" +
                "      \"shipper_id_card\": \"1111111111112X\",\n" +
                "      \"shipper_name\": \"王二1\",\n" +
                "      \"shipper_phone\": \"18112551098\",\n" +
                "      \"shipper_address\": \"资阳市雁江区花花小区\",\n" +
                "      \"shipper_longitude\": \"104.022279\",\n" +
                "      \"shipper_latitude\": \"30.582675\",\n" +
                "      \"shipper_is_realname\": \"1\",\n" +
                "      \"shipment_date\": \"111111112\",\n" +
                "      \"shipper_goods_photo\": \"mZkc2YKNDewqeNDMyNDMyNDMyNDMyNA\",\n" +
                "      \"goods_name\": \"鞋子\",\n" +
                "      \"consignee_name\": \"小马\",\n" +
                "      \"consignee_phone\": \"18233109867\",\n" +
                "      \"consignee_address\": \"成都市新都区好的区\",\n" +
                "      \"receiver_id\": \"100001\",\n" +
                "      \"shipment_area_number\": \"100001\",\n" +
                "      \"shipper_tag\": \"1\"\n" +
                "    }\n" +
                "  ]\n" +
                "}\n";
        CheckJsonExpress checkJson = new CheckJsonExpress();
        try {
            Map retMap = checkJson.validateJsonParams(jsonStr, true);
            System.out.println(retMap.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }*/

    private static String getJsonStr(String filePath) throws IOException {
        BufferedInputStream bufferedInputStream = (BufferedInputStream) Resources
                .getResource(filePath).getContent();
        StringBuffer sbf = new StringBuffer();
        byte[] bt = new byte[2048];
        int count = 0;
        //read返回 -1 时，证明已经遍历完
        while ((count = bufferedInputStream.read(bt)) > 0) {
            sbf.append(new String(bt, 0, count, "UTF-8"));
        }
        return sbf.toString();
    }
}
